package com.insigma.business.qrcode.soldier.util;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.insigma.business.qrcode.common.vo.ProcessStatusEnum;
import com.insigma.business.qrcode.soldier.dto.CheckStatusEnum;
import org.apache.logging.log4j.util.Strings;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class TwoLevelCheckUtils {

    public static String buildCheckStatus(String status, String level, String checkResult) {
        Integer li = Integer.valueOf(level);
        if (li.equals(1)) {
            String before = ProcessStatusEnum.DEALING.name();
            String after = "1_" + checkResult;
            return status.replace(before, after);
        } else {
            String before = (li - 1) + "_" + ProcessStatusEnum.SUCCESS.name();
            String after = li + "_" + checkResult;
            return status.replace(before, after);
        }
    }

    public static Boolean checkHasPassed(String status) {
        String flag = "h_" + ProcessStatusEnum.SUCCESS.name();

        return status.contains(flag);
    }

    public static Boolean checkHasPassed(String status, String checkType) {
        String flag = checkType + "_h_" + ProcessStatusEnum.SUCCESS.name();

        return status.contains(flag);
    }


    public Boolean isHasAuth(String status, String type) {

        return null;
    }

    private List<String> buildStatus(String status, String level) {
        if (Strings.isBlank(status)) {
            return null;
        }

        List<String> statusList = Lists.newArrayList();
        if ("1".equals(level)) {
            if (status.equals(CheckStatusEnum.DEALING.name())) {
                statusList.add(CheckStatusEnum.DEALING.name());
            }
            if (status.equals(ProcessStatusEnum.SUCCESS.name())) {
                statusList.add("1_" + ProcessStatusEnum.SUCCESS.name());
            }
        } else {
            Integer i = Integer.valueOf(level);
            if (status.equals(CheckStatusEnum.DEALING.name())) {
                statusList.add((i - 1) + "_" + ProcessStatusEnum.SUCCESS.name());
            }
            if (status.equals(ProcessStatusEnum.SUCCESS.name())) {
                statusList.add(i + "_" + ProcessStatusEnum.SUCCESS.name());
                statusList.add(i + "_" + ProcessStatusEnum.REJECT.name());
            }
        }
        return statusList;
    }

    public static void main(String[] args) {












        String a = FileUtil.readString("C:\\Users\\jin\\Desktop\\ggg", "utf-8");
        String[] split = a.split("\r\n");
        int i = 1;
        for (String s : split) {
            System.out.println(i++);
            System.out.println(s);
            Map<String, String> header = new HashMap<>();
            header.put("Authorization", "eb882dc6-22e2-4658-8908-93536b391a98");
            header.put("Accept", "application/json, text/plain, */*");

            String s1 = OkHttp3Util.sendByGetUrlWithHeader("http://115.227.32.4:8081/api/account/initPwd?userId="+s, header);
            System.out.println(s1);
        }
    }

    public static void convertLng(String id, double lng, double lat) {
        double PI = Math.PI * 3000.0 / 180.0;
        double x = lng - 0.0065;
        double y = lat - 0.006;
        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI);
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI);
        double gg_lng = z * Math.cos(theta);
        double gg_lat = z * Math.sin(theta);
        System.out.println(id + ","+ gg_lng + "," + gg_lat);
    }

    public static String getRelativeUrl(String name, String path) {
        String upload = OkHttp3Util.upload("http://172.18.103.240:36680/v1/ss/new/upload", path, name);
        System.out.println(upload);
        JSONObject object = JSONObject.parseObject(upload);
        return object.getJSONObject("data").getString("relativePath");
    }

    private static void traversalFile(String path, Map<String, String> map) {
        File file = new File(path);
        File[] fs = file.listFiles();
        for (File f : fs) {
            if (f.isDirectory()) {
                traversalFile(f.getPath(), map);
            }
            if (f.isFile()) {
                System.out.println(f);
                map.put(f.getName(), f.getPath());
                System.out.println();
            }
        }
    }

}
